﻿namespace KxParser.Parser.LR0
{
    class TableAction
    {
        public enum EAction
        {
            Shift,
            Reduce,
            Goto,
            Accept,
            Error
        }

        public EAction Action { get; set; }
        public int Data { get; set; }

        public override string ToString()
        {
            switch (Action)
            {
                case EAction.Accept:
                    return "acc";
                case EAction.Shift:
                    return "s_"+Data;
                case EAction.Reduce:
                    return "r_"+Data;
                case EAction.Goto:
                    return "g_"+Data;
                case EAction.Error:
                    return "err";
            }
            return Global.EmptyCell;
        }

        public override bool Equals(object obj)
        {
            if (!typeof(TableAction).IsAssignableFrom(obj.GetType()))
                return false;

            return Action == ((TableAction)obj).Action && Data == ((TableAction)obj).Data;
        }
    }
}
